<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="0">
    <title>注册</title>
    <link rel="stylesheet" href="../../css/base.css">
    <link rel="stylesheet" href="../../css/element.css">
</head>
<body style="background:url('../../images/bg1.jpg') no-repeat; background-size: cover;">
    <div id="wrapper">
        <div style="width: 400px; margin: 150px auto;background-color:rgba(100,149,237,0.5); border-radius: 10px">
            <div style="width: 100%; height: 100px; color: #eee; font-size: 30px;line-height: 100px; text-align: center">欢迎注册</div>
            <div style="margin-top: 25px; width: 100%; height: 350px; text-align: center">
                <input v-model="user.username" type="text" style="border: 1px solid #ccc; height: 40px; padding: 10px; width: 60%" placeholder="请输入账号">
                <input v-model="user.password" type="password" style="border: 1px solid #ccc; height: 40px; padding: 10px; width: 60%; margin-top: 20px" placeholder="请输入密码">
                <input v-model="user.email" type="text" style="border: 1px solid #ccc; height: 40px; padding: 10px; width: 60%;  margin-top: 20px" placeholder="请输入邮箱">
                <input v-model="user.phone" type="text" style="border: 1px solid #ccc; height: 40px; padding: 10px; width: 60%;  margin-top: 20px" placeholder="请输入电话">
                <button @click="register" style="height: 40px; padding: 10px; width: 60%; margin-top: 25px; background-color: steelblue; color: white">注册</button>
                <div style="margin-top: 25px">
                    <a style="width: 60%; text-align: right; display: inline-block; color: #eee" href="login.html">已有账号，去登录</a>
                </div>
            </div>
        </div>
    </div>

    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/vue.min.js"></script>
    <script src="../../js/element.js"></script>

    <script>
        new Vue({
            el: "#wrapper",
            data: {
                user: {}
            },
            methods: {
                register() {
                    if (!this.user.username) {
                        this.$message({
                            message: "请输入用户名",
                            type: "error"
                        });
                        return;
                    }
                    if (!this.user.password) {
                        this.$message({
                            message: "请输入密码",
                            type: "error"
                        });
                        return;
                    }
                    $.ajax({
                        url: "/api/user/register",
                        type: "POST",
                        contentType: "application/json",
                        data: JSON.stringify(this.user)
                    }).then(res => {
                        if (res.code === '0') {
                            this.$message({
                                message: "注册成功",
                                type: "success"
                            });
                            sessionStorage.setItem("user", JSON.stringify(res.data));
                            setTimeout(() => {
                                location.href= "/page/end/login.html"
                            }, 1000)
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            })
                        }
                    })
                }
            }
        })
    </script>
</body>
</html>
